package cn.zhf.shop.controller;

import cn.zhf.shop.entity.ConsoleUser;
import cn.zhf.shop.entity.Message;
import cn.zhf.shop.entity.search.ClassUserSearch;
import cn.zhf.shop.entity.search.ConsoleUserSearch;
import cn.zhf.shop.service.ConsoleUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@Api(tags = "系统成员管理")
@RequestMapping("/api/ConsoleUser")
public class ConsoleUserController {
    @Resource
    private ConsoleUserService consoleUserService;
    private Logger logger= LoggerFactory.getLogger(getClass());

    @ApiOperation(value = "登录")
    @PostMapping("/login")
    public Message doLog(String username,String password){
        logger.info("C登录查询：username：{},password:{}",username,password);
        return consoleUserService.getByUsername(username,password);
    }

    @ApiOperation(value = "获取用户信息")
    @GetMapping("/")
    public Message<ConsoleUser> getUser(int userId){
        return consoleUserService.selectByUserId(userId);
    }

    @ApiOperation(value = "获取用户列表")
    @GetMapping("/all")
    public Message getAll(){
        return consoleUserService.selectAll();
    }

    @ApiOperation("删除用户")
    @GetMapping("/remove")
    public Message removeUserById(int userId){
        return consoleUserService.removeById(userId);
    }

    @ApiOperation("添加用户")
    @PostMapping("/append")
    public Message append(ConsoleUser user){
        user.setRegistrationTime(new Date());
        return consoleUserService.appendUser(user);
    }

    @ApiOperation("注销")
    @PostMapping("/logout")
    public Message logout(){
        return Message.success("注销成功");
    }

    @ApiOperation("修改密码")
    @PostMapping("/pwd")
    public Message updatePwd(int userId,String pwd){
        return consoleUserService.updatePwd(userId, pwd);
    }

    @ApiOperation("模糊搜索")
    @PostMapping("/mohu/search")
    public Message<List<ConsoleUser>> mohusearch(String str){
        return consoleUserService.selectByUserIdAndOrgIdAndUserGroupAndUsername(str);
    }

    @ApiOperation("条件搜索")
    @PostMapping("/confident/search")
    public Message<List<ConsoleUser>> selectByUserIdAndOrgIdAndUserGroupAndUsername2(Integer userId, Integer orgId, Integer userGroup, String username){

        return consoleUserService.selectByUserIdAndOrgIdAndUserGroupAndUsername2(userId, orgId, userGroup, username);
    }

    @ApiOperation("修改用户")
    @PutMapping("/user")
    public Message update(ConsoleUser consoleUser){
        return consoleUserService.updateByPrimaryKeySelective(consoleUser);
    }

    @ApiOperation("根据user_group查找用户名字")
    @GetMapping("/userGroup")
    public Message<List<ConsoleUser>> selectByUserGroup(int userGroup){
        return consoleUserService.selectByUserGroup(userGroup);
    }


    @ApiOperation("根据user_group查找用户名字(推荐人专用)")
    @GetMapping("/userGroup1")
    public Message<List<ConsoleUser>> selectByUserGroup1(int userGroup){
        return consoleUserService.selectByUserGroup1(userGroup);
    }

    @ApiOperation("代理人界面查询所有代理人")
    @GetMapping("/all/2")
    public Message selectByUserId2(){
        return consoleUserService.selectByUserId2();
    }

    @ApiOperation("用户名重名判断")
    @PostMapping("/judgment/userName")
    public Message judgmentUserName(String userName){
        return consoleUserService.judgmentUserName(userName);
    }

    @ApiOperation(value = "多条件组合模糊查询")
    @PostMapping("/mohu/condition/search")
    public Message mohuConditionSearch(ConsoleUserSearch c){
        return consoleUserService.mohuConditionSearch(c);
    }


    @ApiOperation(value = "根据userGroup获取负责人昵称+真实姓名")
    @GetMapping(value = "/all/head/reallyNameandName/userGroup")
    public Message getAllHeadreallyNameandNameByuserGroup(int userGroup){
        return consoleUserService.getAllHeadreallyNameandNameByuserGroup(userGroup);
    }

    @ApiOperation(value = "根据userId获取负责人昵称+真实姓名")
    @GetMapping(value = "/all/head/reallyNameandName/userId")
    public Message getAllHeadreallyNameandNameByUserId(int userId){
        return consoleUserService.getAllHeadreallyNameandNameByUserId(userId);
    }

    @ApiOperation(value = "直辖代理人添加下属代理人")
    @PostMapping("/add/subordinate")
    public Message addSubordinate(int userId,ConsoleUser consoleUser){
        consoleUser.setRegistrationTime(new Date());
        return consoleUserService.addSubordinate(userId, consoleUser);
    }

    @ApiOperation(value = "直辖代理人查询旗下属代理人")
    @PostMapping("/id/subordinate")
    public Message getSubordinateById(int userId){
        return consoleUserService.getSubordinateById(userId);
    }

    @ApiOperation(value = "直辖代理人模糊查询旗下属代理人")
    @PostMapping("/id/subordinateMohuSearch")
    public Message getSubordinateByIdMohuSearch(int userId,String str){
        return consoleUserService.getSubordinateByIdMohuSearch(userId,str);
    }


    @ApiOperation(value = "修改用户对用户名进行验证")
    @GetMapping("/judgment/update/userName")
    public Message judgmentupdateuserName(int userid,String userName){
        return consoleUserService.judgmentupdateuserName(userid,userName);
    }

    @ApiOperation(value = "查所有consoleUser除了代理人的（userGroup=2）")
    @GetMapping("/all/exceptUsereGroup2")
    public Message selectAllexceptUsereGroup2(){
        return consoleUserService.selectAllexceptUsereGroup2();
    }

    @ApiOperation(value = "代理人模糊查询")
    @GetMapping("/userGroup2/mohuSearch")
    public Message userGroup2MohuSearch(String str){
        return consoleUserService.userGroup2MohuSearch(str);
    }
}
